/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package genetic;

import dmcn.bl.genetics.input.Input;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Random;

/**
 *
 * @author skyr
 */
public class GeneticController {

    private Input input;

    public GeneticController(Input input) {
        this.input = input;
    }

    public void selection(Collection<Solution> solutions) {
        /*
         * TODO selection
         *
         * ypologismos sunolikou kostous lusewn
         *
         * tuxaia epilogh n ari8mwn r apo to 1 ews to sunoliko kostos
         *
         * epilogh twn lusewn me r in (sunoliko kostos - diko tous kostos)
         */
        double costFull = 0;
        for (Iterator<Solution> it = solutions.iterator(); it.hasNext();) {
            Solution solution = it.next();
            costFull = costFull + solution.getCost();
        }
        GeneralController.sortSolutions(solutions);
        Random random = new Random();
        Solution[] randoms = new Solution[GeneralController.maxSolutionNumber - 2];
        int i = 0;
        int r;
        while (i < randoms.length) {
            r = random.nextInt((int) costFull);
            for (Iterator<Solution> it = solutions.iterator(); it.hasNext();) {
                Solution solution = it.next();
                if (r > (costFull - solution.getCost())) {
                    randoms[i] = solution;
                    i++;
                }
            }
        }
    }

    public void crossover() {
    }

    public void mutation() {
    }

    public void replacement() {
    }
}
